package org.wd.extractor.cleartrip;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class WebdriverUtil {
	public static List<List<String>> getTableContents(WebDriver driver, String xpath) {
		WebElement table = driver.findElement(By.xpath(xpath));
		List<WebElement> allRows = table.findElements(By.tagName("tr"));
		List<List<String>> rowContents = new ArrayList<List<String>>();
		// int i = 0;
		for (WebElement row : allRows) {
			List<String> cellContents = new ArrayList<String>();
			List<WebElement> cells = row.findElements(By.tagName("td"));
			for (WebElement cell : cells) {
				cellContents.add(cell.getText().replaceAll("[\\n\\r\\t]+", " "));
			}
			rowContents.add(cellContents);
			// System.out.println("done row: " + i++);
		}
		return rowContents;
	}
}
